﻿namespace QASPRibbon.Commands
{
    internal class RibbonCommand
    {
        public string ActionScript { get; private set; }
        public string EnabledScript { get; private set; }
        public string ControlId { get; private set; }
        public string CommandId { get; private set; }

        public RibbonCommand(string controlId, string commandId, string clientScript, string enabledScript)
        {
            ControlId = controlId;
            CommandId = commandId;
            ActionScript = clientScript;
            EnabledScript = enabledScript;
        }

        public RibbonCommand(string controlId, string commandId, string clientScript):this(controlId, commandId, clientScript, "true")
        {
        }

        internal string FullId { get { return ControlId + (IsStateCheck ? "QueryCommand" : CommandId); } }

        public override string ToString()
        {
            return ControlId + CommandId;
        }

        internal bool IsStateCheck { get { return CommandId == "CheckState"; } }

        internal string ToCheckStateScript()
        {
            return !IsStateCheck
                       ? string.Format("if (commandId == '{0}{1}') {{ return {2}; }}", ControlId, CommandId,
                                       EnabledScript)
                       : string.Format("if (commandId == '{0}Command') {{ {1}; }}", ControlId,
                                       ActionScript);
        }

        internal string ToActionScript()
        {
            return string.Format("if (commandId == '{0}{1}') {{ {2}; return true; }}", ControlId, CommandId,
                                 ActionScript);
        }
    }
}
